<?php

/**
 * ReservasPersonas form.
 *
 * @package    costabravasfr
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ReservasPersonasForm extends BaseReservasPersonasForm
{
  public function configure()
  {
	unset($this['reserva_id'], $this['created_at'], $this['updated_at']); 
	//En este formulario quien se inscribe es el responsable de la reserva
	$this->setDefault('responsablereserva', '1');
	//En este formulario quien se inscribe es el responsable de la reserva
	$this->setDefault('webreserva', 'BH');
	 //Para el widget de paises, por defecto el de la cultura
	$pais = sfContext::getInstance()->getUser()->getLangCulture();
	if($pais == 'ca'){
		$pais = 'es';
	}
	if($pais == 'en'){
		$pais = 'gb';
	}
	$this->widgetSchema['paisreserva'] = new sfWidgetFormI18nChoiceCountry(array('culture' => sfContext::getInstance()->getUser()->getCulture(), 'add_empty' => true, 'default' => strtoupper($pais)));
	$yearsBirth = range(date("Y")-19, date("Y")-110); 
	$yearsDocument = range(date("Y"), date("Y")+20);
	$sexoreserva = array('' =>'', 'M' =>sfContext::getInstance()->getI18N()->__('mujer', null, 'forms'), 'H' => sfContext::getInstance()->getI18N()->__('hombre', null, 'forms'));
	$tipodocumentoreserva = array('' =>'', 'D' =>sfContext::getInstance()->getI18N()->__('dni', null, 'forms'), 'P' => sfContext::getInstance()->getI18N()->__('pasaporte', null, 'forms'), 'N' => sfContext::getInstance()->getI18N()->__('permisoresidenciaespanol', null, 'forms'));
	$this->widgetSchema['sexoreserva'] = new sfWidgetFormSelect(array('choices' => $sexoreserva));
	$this->widgetSchema['emailreservaconfirmate'] = new sfWidgetFormInputText();
	$this->widgetSchema['tipodocumentoreserva'] = new sfWidgetFormSelect(array('choices' => $tipodocumentoreserva));
	
	//$preftelefonosint = array('' =>'', '43' =>'+43 Austria', '32' => 'Belgium', '385' => 'Croatia', '420' => 'Czech Republic');
	//$this->widgetSchema['preftelefono1reserva'] = new sfWidgetFormSelect(array('choices' => $preftelefonosint));
	
	$this->widgetSchema['fechanacreserva'] = new sfWidgetFormDate(
		array('years' => array_combine($yearsBirth, $yearsBirth), 'format'=>'%day% %month% %year%')
	);
	/*$this->widgetSchema['fechaexpeddnipasaporte'] = new sfWidgetFormDate(
		array('years' => array_combine($yearsDocument, $yearsDocument), 'format'=>'%day% %month% %year%')
	);*/
	$this->widgetSchema['numadultos'] = new sfWidgetFormInputText();
	$this->widgetSchema['numninos'] = new sfWidgetFormInputText();
	$this->widgetSchema['numbebes'] = new sfWidgetFormInputText();
	$this->widgetSchema['numcunas'] = new sfWidgetFormInputText();
	$this->widgetSchema['numtronas'] = new sfWidgetFormInputText();
	$this->widgetSchema['preciototalreserva'] = new sfWidgetFormInputHidden();
	$this->widgetSchema['preciosabanas'] = new sfWidgetFormInputHidden();
	$this->widgetSchema['webreserva'] = new sfWidgetFormInputHidden();
	
	$this->widgetSchema['responsablereserva'] = new sfWidgetFormInputHidden();
	
	$opciones = array('0' =>'');
	$this->setWidget('incluirsabanas', new sfWidgetFormSelectCheckbox(array('choices' => $opciones)));
	$this->setWidget('aceptoterminos', new sfWidgetFormSelectCheckbox(array('choices' => $opciones)));
	$this->setWidget('seguroanulacion', new sfWidgetFormSelectCheckbox(array('choices' => $opciones)));
	
	$this->widgetSchema->setLabel('nombrereserva', sfContext::getInstance()->getI18N()->__('nombrereserva', null, 'forms'));
	$this->widgetSchema->setLabel('apellidosreserva', sfContext::getInstance()->getI18N()->__('apellidosreserva', null, 'forms'));
	$this->widgetSchema->setLabel('sexoreserva', sfContext::getInstance()->getI18N()->__('sexoreserva', null, 'forms'));
	$this->widgetSchema->setLabel('fechanacreserva', sfContext::getInstance()->getI18N()->__('fechanacreserva', null, 'forms'));
	$this->widgetSchema->setLabel('emailreserva', sfContext::getInstance()->getI18N()->__('emailreserva', null, 'forms'));
	$this->widgetSchema->setLabel('emailreservaconfirmate', sfContext::getInstance()->getI18N()->__('emailreservaconfirmate', null, 'forms'));
	$this->widgetSchema->setLabel('tipodocumentoreserva', sfContext::getInstance()->getI18N()->__('tipodocumentoreserva', null, 'forms'));
	$this->widgetSchema->setLabel('dnipasaportereserva', sfContext::getInstance()->getI18N()->__('dnipasaportereserva', null, 'forms'));
	$this->widgetSchema->setLabel('preftelefono1reserva', sfContext::getInstance()->getI18N()->__('preftelefono1reserva', null, 'forms'));
	$this->widgetSchema->setLabel('telefono1reserva', sfContext::getInstance()->getI18N()->__('telefono1reserva', null, 'forms'));
	$this->widgetSchema->setLabel('telefono2reserva', sfContext::getInstance()->getI18N()->__('telefono2reserva', null, 'forms'));
	$this->widgetSchema->setLabel('addressreserva', sfContext::getInstance()->getI18N()->__('addressreserva', null, 'forms'));
	$this->widgetSchema->setLabel('codigopostalreserva', sfContext::getInstance()->getI18N()->__('codigopostalreserva', null, 'forms'));
	$this->widgetSchema->setLabel('localidadreserva', sfContext::getInstance()->getI18N()->__('localidadreserva', null, 'forms'));
	$this->widgetSchema->setLabel('paisreserva', sfContext::getInstance()->getI18N()->__('paisreserva', null, 'forms'));
	$this->widgetSchema->setLabel('numadultos', sfContext::getInstance()->getI18N()->__('numadultos', null, 'forms'));
	$this->widgetSchema->setLabel('numninos', sfContext::getInstance()->getI18N()->__('numninos', null, 'forms'));
	$this->widgetSchema->setLabel('numbebes', sfContext::getInstance()->getI18N()->__('numbebes', null, 'forms'));
	$this->widgetSchema->setLabel('numtronas', sfContext::getInstance()->getI18N()->__('numtronas', null, 'forms'));
	$this->widgetSchema->setLabel('numcunas', sfContext::getInstance()->getI18N()->__('numcunas', null, 'forms'));
	$this->widgetSchema->setLabel('aceptoterminos', sfContext::getInstance()->getI18N()->__('aceptoterminos', null, 'forms'));
	
	
	  $this->setValidators(array(
	  'nombrereserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorNombrereserva', null, 'forms'))),
	  'apellidosreserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorApellidosreserva', null, 'forms'))),
	  'sexoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorSexoreserva', null, 'forms'))),
	  'fechanacreserva'       => new sfValidatorDate(array(), array('required' => sfContext::getInstance()->getI18N()->__('errorFechanacreserva', null, 'forms'), 'invalid' => 'Fecha de nacimiento no valida')),
	  'emailreserva' => new sfValidatorEmail(array(), array('required' => sfContext::getInstance()->getI18N()->__('errorEmailreserva', null, 'forms')), array('invalid' => sfContext::getInstance()->getI18N()->__('errorEmailreserva', null, 'forms'))),
	  'emailreservaconfirmate' => new sfValidatorEmail(array(), array('required' => sfContext::getInstance()->getI18N()->__('errorEmailreserva', null, 'forms')), array('invalid' => sfContext::getInstance()->getI18N()->__('errorEmailreserva', null, 'forms'))),
	  'dnipasaportereserva'       => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('errorDnipasaportereserva', null, 'forms'))),
	  'tipodocumentoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorTipodocumentoreserva', null, 'forms'))),
	  //'fechaexpeddnipasaporte'       => new sfValidatorDate(array(), array('required' => 'Especifique la fecha de expedicion de su documento responsable de la reserva', 'invalid' => 'Fecha de expedicion de documento no valida')),
	  'preftelefono1reserva'       => new sfValidatorString(array(), array('max_length' => 6, 'required' => sfContext::getInstance()->getI18N()->__('errorPreftelefono1reserva', null, 'forms'))),
	  'telefono1reserva'       => new sfValidatorString(array(), array('max_length' => 30, 'required' => sfContext::getInstance()->getI18N()->__('errorTelefono1reserva', null, 'forms'))),
	  'preftelefono2reserva'       => new sfValidatorString(array('required' => false), array('max_length' => 6)),
	  'telefono2reserva'       => new sfValidatorString(array('required' => false), array('max_length' => 30)),
	  'addressreserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorAddressreserva', null, 'forms'))),
	  'codigopostalreserva'       => new sfValidatorString(array(), array('max_length' => 10, 'required' => sfContext::getInstance()->getI18N()->__('errorCodigopostalreserva', null, 'forms'))),
	  'localidadreserva'       => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('errorLocalidadreserva', null, 'forms'))),
	  'paisreserva'       => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('errorPaisreserva', null, 'forms'))),
	  'responsablereserva'     => new sfValidatorBoolean(array('required' => true)),
	  'webreserva'     => new sfValidatorString(array('required' => true), array('max_length' => 2)),
	  'numninos'                  => new sfValidatorString(array(), array('max_length' => 3, 'required' => sfContext::getInstance()->getI18N()->__('errorNumninos', null, 'forms'))),
	  //'numbebes'                  => new sfValidatorString(array(), array('max_length' => 3, 'required' => 'Especifique el nunero de bebes')),
      'numadultos'       => new sfValidatorString(array(), array('max_length' => 3, 'required' => sfContext::getInstance()->getI18N()->__('errorNumadultos', null, 'forms'))),
	  'aceptoterminos' => new sfValidatorChoice(array('choices' => array($opciones)), array('required' => sfContext::getInstance()->getI18N()->__('errorAceptoterminos', null, 'forms')))
    ));
	
	
	$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('emailreserva', '==', 'emailreservaconfirmate', array(),
       array('invalid' => sfContext::getInstance()->getI18N()->__('errorEmailreservanocoinc', null, 'forms'))));
	   
	$this->validatorSchema->setOption('allow_extra_fields', true);
	
  }
  
   public function checkPassword($validator, $values)
  {
	if ($values['aceptoterminos'] == '')
    {
      // password is not correct, throw an error
      throw new sfValidatorError($validator, sfContext::getInstance()->getI18N()->__('errorAceptoterminos', null, 'forms'));
    }
 
    // password is correct, return the clean values
    return $values;
  }
  
}
